home *** CD-ROM | disk | FTP | other *** search
- /**************************************************************************************************
- * myFunctions.c
- *
- * This is the file where you (the programmer) will put your code. The three functions
- * below are the skeletal parts of what you must fill in. Just enter your code into each
- * corresponding function, compile, and link with the ImagicXFunction Library. Then, you
- * are done.
- *
- * See Documentation for further help. All of your answers should be answered there.
- *
- * For more complex and technical questions that the documentation could not answer,
- * contact me, Brian Powell:
- *
- * (E-Mail is the best way. Preferably Internet)
- * Internet : powellb@boulder.colorado.edu
- * AppleLink: d3706
- *
- * (If you have no other means...)
- * Brian Powell
- * Colorado Center for Astrodynamics Research
- * University of Colorado at Boulder
- * Campus Box 431
- * Boulder, CO 80309
- * (303) 492-6677
- *************************************************************************************************/
-
- #include "XFunctions.h"
- #include <stdio.h>
-
- /* Declare any functions you may create here.
- */
- pascal void Border(Rect);
-
- /* This is called whenever Imagic is beginning. You set up your parameters here. If there is
- * anything you want to initialize, do that here.
- */
- pascal OSErr Initialize(theParameters)
- InitStruct *theParameters;
- {
- OSErr theError = noErr;
-
- /* Insert Your Parameters Here. If these parameters are fine with you, leave them,
- * otherwise set them up for your own needs. This is also the default settings, so don't
- * change it unless you need to.
- */
-
- theParameters->Filter = FALSE;
- theParameters->NumOfImages = 3;
-
- /* Make sure that we are not goint to crash Imagic on startup with wrong calls.
- */
- if (GetVersion() < EXTERNAL_FUNCTION_LIBRARY_VERSION_NUM)
- return (theError);
-
- /* Insert your initialization code here.
- */
-
- /* Let's go back to Imagic, giving it the parameters for our external module. */
- return (theError);
- }
-
- /* This function is called whenever the user selects your command from the menu. This is the
- * heart of your function.
- */
- pascal OSErr ExecuteMenu()
- {
- OSErr theError=noErr;
- ImageHandle image;
- ImageList images;
- PixelValPtr values1, values2, values3, newvals;
- long computed;
- int x, y, nx, ny, tx, ty, i, j;
- int number;
- Point topleft, botright;
- short proj;
- char string[256], dummy[256];
-
-
- /* Ask the user for three images.
- */
-
- if ((images = GetImageList(3,3,"Select 3 Images", &number)) == NIL)
- return (theError);
-
- /* Get the size of one image.
- * NOTE: You should check to make sure that all of the images are of the same size;
- * otherwise, things will get messed up.
- */
- GetImageSize((*images)[0], &x, &y);
- GetImageSize((*images)[1], &nx, &ny);
- GetImageSize((*images)[2], &tx, &ty);
- if (x!=nx || x!=tx || y!=ny || y!=ty)
- return (theError);
-
- /* Get the geography of one of the images. We'll just sit it the new one to the
- * first one.
- */
- GetImageGeography((*images)[0], &topleft, &botright, &proj);
-
- /* Create an image
- */
- if ((image = NewBlankImage("Average", x, y, TRUE, &topleft, &botright, proj)) == NIL)
- return (theError);
-
- /* Set up memory
- */
- newvals = (PixelValPtr)CreateNewPtr(x);
-
- /* Loop through grabbing information from each image and combine it.
- */
- if (BeginImageWork(image, FALSE)) {
- if (!CreateProgressDialog("Computing Average", 0)) return;
- for (i=0; i<y; i++) {
- GetPixLineVal((*images)[0], &values1, i, 0);
- GetPixLineVal((*images)[1], &values2, i, 0);
- GetPixLineVal((*images)[2], &values3, i, 0);
- for (j=0; j<x; j++) {
- computed = (long)((values1[j]+values2[j]+values3[j])/3);
- newvals[j] = (PixelVal)computed;
- }
- SetPixLineVal(image, newvals, i, 0);
- if (!UpdateProgressDialog((double)i/(double)y*100)) break;
- }
- }
-
- /* Clear things up.
- */
- DestroyPtr(newvals);
- DisposProgressDialog();
- EndImageWork(image);
- return (theError);
- }
-
- /* This function is called whenever Imagic quits. If you need to clear anything up before it
- * quits, do so here.
- */
- pascal OSErr Exit()
- {
- OSErr theError = noErr;
-
- /* Insert your shut-down code here. Deallocate anything you may have left around, Do
- * anything you may need to do as Imagic is quitting.
- */
-
- /* Let's let Imagic quit, returning an error that may have occured.
- */
- return (theError);
- }
-